part of '../repository.dart';

abstract class _PurchasedItemTransactionDtoFactory {
  static _PurchasedItemTransactionDto fromJson(Map<String, dynamic> json) {
    final type = json[_kPurchasedItemTransactionTypeKey] as String;

    if (type == _kOneTimePurchasedItemTransactionTypeValue) {
      return _OneTimePurchasedItemTransactionDto.fromJson(json);
    }

    if (type == _kPurchasedSubscriptionTransactionTypeValue) {
      return _PurchasedSubscriptionTransactionDto.fromJson(json);
    }

    throw UnimplementedError();
  }

  static _PurchasedItemTransactionDto fromEntity(
      GooglePlayTransaction purchasedItemTransaction) {
    if (purchasedItemTransaction is GooglePlayOneTimePurchasedItemTransaction) {
      return _OneTimePurchasedItemTransactionDto.fromEntity(purchasedItemTransaction);
    }

    if (purchasedItemTransaction is GooglePlayPurchasedSubscriptionTransaction) {
      return _PurchasedSubscriptionTransactionDto.fromEntity(purchasedItemTransaction);
    }

    throw UnimplementedError();
  }
}
